import Vue from 'vue'
import Router from 'vue-router'
import store from '../vuex/index'
Vue.use(Router)

let router = new Router({
	routes: [
		{
			path: '/',
			component: resolve => {
          require(['../view/login/login.vue'], res => {
              resolve(res)
          })
      }
    },
    {
      path:'/cache-manager',
      name:'cache-manager',
      component:resolve=>{
          require(['../view/tools/cache-manager.vue'], res => {
              resolve(res)
          })
      }
    },
		{
			path: '/login',
			name: 'login',
			component: resolve => {
          require(['../view/login/login.vue'], res => {
              resolve(res)
          })
      }
		},
		{
			path: '/vip-cards',
			name: 'vip-cards',
			component: resolve => {
          require(['../view/group-vip/vip-cards.vue'], res => {
              resolve(res)
          })
      }
		},
		{
			path: '/index',
			name: 'index',
			component: resolve => {
          require(['../view/index.vue'], res => {
              resolve(res)
          })
      },
			meta: {
				title: '首页'
			},
			children:[
				{
					path: '/home',
					name: 'home',
					meta: { menu: 'home',name:'首页',menuCrumbs:[{name:'首页',url:'home'}] },
          components: {
            default: (resolve) => require(['../view/home.vue'], resolve),
          }
				},
				{
          path: '/group-orderlists',
          name: 'group-orderlists',
          meta: { menu: 'group-orderlists',type:'group-order',name:'集团订单',menuCrumbs:[{name:'集团订单管理',url:'group-orderlists'},{name:'集团订单',url:'group-orderlists'}] },
          components: {
            hasMenu: (resolve) => require(['../view/group-order/group-orderlists.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
				{
          path: '/group-lists',
          name: 'group-lists',
          meta: { menu: 'group-lists',type:'group-order',name:'全部订单',menuCrumbs:[{name:'集团订单管理',url:'group-orderlists'},{name:'全部订单',url:'group-lists'}] },
          components: {
            hasMenu: (resolve) => require(['../view/group-order/group-lists.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
        {
          path: '/group-reserve',
          name: 'group-reserve',
          meta: { menu: 'group-reserve',type:'group-order',name:'集团预定',menuCrumbs:[{name:'集团订单管理',url:'group-orderlists'},{name:'集团预定',url:'group-reserve'}] },
          components: {
            hasMenu: (resolve) => require(['../view/group-order/group-reserve.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
        {
          path: '/user-lists',
          name: 'user-lists',
          meta: { menu: 'user-lists',name:'客户列表',type:'group-user',menuCrumbs:[{name:'集团客户管理',url:'group-orderlists'},{name:'客户列表',url:'group-orderlists'}] },
          components: {
            hasMenu: (resolve) => require(['../view/group-vip/user-lists.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
        {
          path: '/vip-lists',
          name: 'vip-lists',
          meta: { menu: 'vip-lists',name:'会员列表',type:'group-user',menuCrumbs:[{name:'集团客户管理',url:'group-orderlists'},{name:'会员列表',url:'group-orderlists'}] },
          components: {
            default: (resolve) => require(['../view/group-vip/vip-lists.vue'], resolve),
          }
        },
        {
          path: '/group-info',
          name: 'group-info',
          meta: { menu: 'group-info',name:'集团信息',type:'group-manage',menuCrumbs:[{name:'集团设置',url:'group-orderlists'},{name:'集团信息',url:'group-orderlists'}] },
          components: {
            hasMenu: (resolve) => require(['../view/group-manage/group-info.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
        {
          path: '/group-store',
          name: 'group-store',
          meta: { menu: 'group-store',name:'门店信息',type:'group-manage',menuCrumbs:[{name:'集团设置',url:'group-orderlists'},{name:'门店信息',url:'group-orderlists'}] },
          components: {
            hasMenu: (resolve) => require(['../view/group-manage/group-store.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
        {
          path: '/code-manage',
          name: 'code-manage',
          meta: { menu: 'code-manage',name:'账号管理',type:'group-manage',menuCrumbs:[{name:'集团设置',url:'group-orderlists'},{name:'账号管理',url:'group-orderlists'}] },
          components: {
            hasMenu: (resolve) => require(['../view/group-manage/code-manage.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
        {
          path: '/person-manage',
          name: 'person-manage',
          meta: { menu: 'person-manage',name:'员工管理',type:'group-manage',menuCrumbs:[{name:'集团设置',url:'group-orderlists'},{name:'员工管理',url:'group-orderlists'}] },
          components: {
            hasMenu: (resolve) => require(['../view/group-manage/person-manage.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
        {
          path: '/calendar-room',
          name: 'calendar-room',
          meta: { menu: 'calendar-room',name:'房态管理',type:'calendar-room',menuCrumbs:[{name:'房态管理',url:'calendar-room'}] },
          components: {
            default: (resolve) => require(['../view/store/calendar-room.vue'], resolve),
          }
        },
				{
          path: '/nowcalendar-room',
          name: 'nowcalendar-room',
          meta: { menu: 'nowcalendar-room',name:'缩略房态',type:'nowcalendar-room',menuCrumbs:[{name:'实时房态',url:'nowcalendar-room'}] },
          components: {
            default: (resolve) => require(['../view/store/nowcalendar-room.vue'], resolve),
          }
        },
        {
          path: '/mincalendar-room',
          name: 'mincalendar-room',
          meta: { menu: 'mincalendar-room',name:'缩略房态',type:'mincalendar-room',menuCrumbs:[{name:'缩略房态',url:'mincalendar-room'}] },
          components: {
            default: (resolve) => require(['../view/store/mincalendar-room.vue'], resolve),
          }
        },
        {
          path: '/store-order',
          name: 'store-order',
          meta: { menu: 'store-order',name:'订单管理',type:'order-manage',menuCrumbs:[{name:'订单管理',url:'store-order'}] },
          components: {
            hasMenu: (resolve) => require(['../view/store/store-order.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
        {
          path: '/store-vip',
          name: 'store-vip',
          meta: { menu: 'store-vip',name:'客户管理',type:'person-manage',menuCrumbs:[{name:'客户管理',url:'store-vip'}] },
          components: {
            hasMenu: (resolve) => require(['../view/store/store-vip.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
        {
          path: '/store-info',
          name: 'store-info',
          meta: { menu: 'store-info',name:'消费管理',type:'store-manage',menuCrumbs:[{name:'资源管理',url:'group-orderlists'},{name:'消费管理',url:'store-info'}] },
          components: {
            hasMenu: (resolve) => require(['../view/store-manage/store-info.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
        {
          path: '/store-room',
          name: 'store-room',
          meta: { menu: 'store-room',name:'房型设置',type:'store-manage',menuCrumbs:[{name:'资源管理',url:'store-manage'},{name:'房型设置',url:'store-room'}] },
          components: {
            hasMenu: (resolve) => require(['../view/store-manage/store-room.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
        {
          path: '/store-price',
          name: 'store-price',
          meta: { menu: 'store-price',name:'价格设置',type:'store-manage',menuCrumbs:[{name:'资源管理',url:'store-manage'},{name:'价格设置',url:'store-price'}] },
          components: {
            hasMenu: (resolve) => require(['../view/store-manage/store-price.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
				{
          path: '/policy-info',
          name: 'policy-info',
          meta: { menu: 'policy-info',name:'政策管理',type:'store-manage',menuCrumbs:[{name:'资源管理',url:'store-manage'},{name:'政策管理',url:'policy-info'}] },
          components: {
            hasMenu: (resolve) => require(['../view/store-manage/policy-info.vue'], resolve),
            menu: (resolve) => require(['../components/base/menu.vue'], resolve)
          }
        },
				{
					path: '/zone-info',
					name: 'zone-info',
					meta: { menu: 'zone-info',name:'政策管理',type:'store-manage',menuCrumbs:[{name:'资源管理',url:'store-manage'},{name:'楼层管理',url:'zone-info'}] },
					components: {
						hasMenu: (resolve) => require(['../view/store-manage/zone-info.vue'], resolve),
						menu: (resolve) => require(['../components/base/menu.vue'], resolve)
					}
				},
				{
					path: '/hotel-info',
					name: 'hotel-info',
					meta: { menu: 'hotel-info',name:'政策管理',type:'store-manage',menuCrumbs:[{name:'资源管理',url:'store-manage'},{name:'旅行社管理',url:'hotel-info'}] },
					components: {
						hasMenu: (resolve) => require(['../view/store-manage/hotel-info.vue'], resolve),
						menu: (resolve) => require(['../components/base/menu.vue'], resolve)
					}
				},
				{
					path: '/revenue-excel',
					name: 'revenue-excel',
					meta: { menu: 'revenue-excel',name:'报表',type:'excels',menuCrumbs:[{name:'报表',url:'excels'},{name:'营收报表',url:'revenue-excel'}] },
					components: {
						hasMenu: (resolve) => require(['../view/excels/revenue-excel.vue'], resolve),
						menu: (resolve) => require(['../components/base/menu.vue'], resolve)
					}
				},
				{
					path: '/roomtype-rental',
					name: 'roomtype-rental',
					meta: { menu: 'roomtype-rental',name:'房型出租率统计',type:'excels',menuCrumbs:[{name:'报表',url:'excels'},{name:'房型出租率统计',url:'roomtype-rental'}] },
					components: {
						hasMenu: (resolve) => require(['../view/excels/roomtype-rental.vue'], resolve),
						menu: (resolve) => require(['../components/base/menu.vue'], resolve)
					}
				},
			]
		}
	]
})

router.beforeEach((to, from, next) => {
	if(!sessionStorage.getItem('userList')&&to.name!=='login'){
		sessionStorage.clear();
		next({name:'login'});
	}
	if(!!to.name&&to.path!=='/'){
		store.commit('LOGIN_IN',[to.meta.type,to.meta.name,to.meta.menuCrumbs]);
    let data=JSON.parse(sessionStorage.getItem('nowmenu'))||null;
    if(data){
      _.map(data.childrens,val=>{
        if(val.type===to.meta.type){
          store.commit('SET_MENU',val.childs);
        }
      })
    }
		next();
	}else{
		next({name:'home'});
	}
})
router.afterEach((to, from, next) => {
})

export default router
